package com.ms.app;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Lifecycle;

import com.ms.module.wechat.clear.Details;
import com.ms.module.wechat.clear.WeChatClearListener;
import com.ms.module.wechat.clear.WeChatClearModule;
import com.ms.module.wechat.clear.utils.ByteSizeToStringUnitUtils;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    private void show(String text) {
        Toast.makeText(this, text, Toast.LENGTH_LONG).show();
    }

    private TextView textViewWeChatClear;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        textViewWeChatClear = findViewById(R.id.textViewWeChatClear);
        textViewWeChatClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                // 关闭微信清理模块
                // WeChatClearModule.close();

                // 启动微信清理模块
                WeChatClearModule.start(MainActivity.this, new WeChatClearListener() {


                    @Override
                    public void onNotInstallWeChat() {
                        // 没有安装微信

                        Log.e(TAG, "onNotInstallWeChat: 没有安装微信");
                    }

                    @Override
                    public void onStartTimestamp(long timestamp) {
                        // 启动你的时间戳
                        Log.e(TAG, "onStartTimestamp: 启动时间戳" + timestamp);
                    }

                    @Override
                    public void onEnterWeChatClearScan(Activity activity, Lifecycle.Event lifecycleEvent) {
                        Log.e(TAG, "onEnterWeChatClearScan: 进入扫描页  " + lifecycleEvent.name());
                    }

                    @Override
                    public void onScanFinish(Activity activity, Lifecycle.Event lifecycleEvent, long length) {
                        Log.e(TAG, "onScanFinish: " + lifecycleEvent.name() + "  " + ByteSizeToStringUnitUtils.byteToStringUnit(length));
                    }

                    @Override
                    public void onClearUpNow(Activity activity, long lenth) {
                        Log.e(TAG, "onClearUpNow: " + ByteSizeToStringUnitUtils.byteToStringUnit(lenth));
                    }

                    @Override
                    public void onEnterDetails(Activity activity, Details details, Lifecycle.Event lifecycleEvent) {
                        Log.e(TAG, "onEnterDetails: 进入详情页面 : " + details.name() + "  " + lifecycleEvent.name());
                    }


                    @Override
                    public void onDeleteFile(Activity activity, Details details, long length) {
                        Log.e(TAG, "onDeleteFile: 删除文件 " + details.name() + ByteSizeToStringUnitUtils.byteToStringUnit(length));
                    }

                    @Override
                    public void onClose(Activity activity) {
                        Log.e(TAG, "onClose: 关闭微信清理模块");
                    }

                    /**
                     * 当前扫描垃圾的大小
                     * @param length
                     */
                    @Override
                    public void onCurrentGarbageSize(long length) {
                        Log.e(TAG, "onCurrentGarbageSize: " + length + "    " + ByteSizeToStringUnitUtils.byteToStringUnit(length));
                    }
                });
            }
        });
    }
}
